package otheri.download;

import otheri.common.FileHelper;
import otheri.io.Input;
import otheri.io.Output;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class CommonTest extends Activity {

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		LinearLayout ll = new LinearLayout(this);
		ll.setOrientation(LinearLayout.VERTICAL);

		final FileHelper helper = new FileHelper(this);

		Button buttonReadAndWriteSDCard = new Button(this);
		buttonReadAndWriteSDCard.setText("write & read SDCard");
		buttonReadAndWriteSDCard.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				try {
					Output out = helper.writeSDFile("test.text");
					out.writeUTF8("dkfjalkjfalskdhfkhsadf");
					out.flush();
					out.close();

					Input in = helper.readSDFile("test.text");
					String text = in.readUTF8();
					System.out.println(text);
					in.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});

		Button buttonReadAndWriteFile = new Button(this);
		buttonReadAndWriteFile.setText("write & read File");
		buttonReadAndWriteFile.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				try {
					Output out = helper.wirteFile("test.text");
					out.writeUTF8("dkfjalkjfalskdhfkhsadf");
					out.flush();
					out.close();

					Input in = helper.readFile("test.text");
					String text = in.readUTF8();
					System.out.println(text);
					in.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});

		ll.addView(buttonReadAndWriteSDCard);
		ll.addView(buttonReadAndWriteFile);
		setContentView(ll);
	}
}
